<div id="sysAchievementTable">
    <div class="layui-card layadmin-header">
        <div class="layui-breadcrumb" lay-filter="breadcrumb" style="visibility: visible;">
            <a lay-href="">系统管理</a><span lay-separator="">/</span>
            <a><cite>管理</cite></a>
        </div>
    </div>

    <div class="demoTable">
          <label>完成人id</label>
       <div class="layui-inline">
              <input class="layui-input" name="userId" autocomplete="off">
       </div>
          <label>完成人name</label>
       <div class="layui-inline">
              <input class="layui-input" name="userName" autocomplete="off">
       </div>
          <label>租出去的房子id</label>
       <div class="layui-inline">
              <input class="layui-input" name="houseId" autocomplete="off">
       </div>
          <label>租出去的房子带来公司的收入</label>
       <div class="layui-inline">
              <input class="layui-input" name="housePrice" autocomplete="off">
       </div>
          <label>合同表的id</label>
       <div class="layui-inline">
              <input class="layui-input" name="contractId" autocomplete="off">
       </div>
          <label>录入时间</label>
       <div class="layui-inline">
              <input class="layui-input" name="createTime" autocomplete="off">
       </div>
          <label>操作人id</label>
       <div class="layui-inline">
              <input class="layui-input" name="operId" autocomplete="off">
       </div>
          <label>操作人name</label>
       <div class="layui-inline">
              <input class="layui-input" name="operName" autocomplete="off">
       </div>

       <button class="layui-btn"  lay-submit lay-filter="btnSearch">搜索</button>
    </div>
    <table class="layui-hide" id="dataTable" lay-filter="data-sysAchievement"></table>
</div>

<script>
    var tableIns;
    var openIndex;
    layui.use(["table", "jquery", "form", "laydate", "upload"], function () {
        var table = layui.table
        , $ = layui.jquery
        , form = layui.form
        , laydate = layui.laydate
        , upload = layui.upload;
         tableIns = table.render({
            elem: '#dataTable'
            , url: '/sysAchievement/getSysAchievements'
            , page: true
            , limit: 10
            , height: 'full-200'
            , toolbar:'#toolbarDemo'
            , limits: [10, 20, 30,50,100]
            , cols: [[
                {type: 'numbers'}
               , {field: 'userId', title: '完成人id'}
               , {field: 'userName', title: '完成人name'}
               , {field: 'houseId', title: '租出去的房子id'}
               , {field: 'housePrice', title: '租出去的房子带来公司的收入'}
               , {field: 'contractId', title: '合同表的id'}
               , {field: 'createTime', title: '录入时间'}
               , {field: 'operId', title: '操作人id'}
               , {field: 'operName', title: '操作人name'}
                , {fixed: 'right', title: '操作', align: 'center', width: 178, toolbar: '#barDemo'}
            ]]
        });

        //头工具栏事件
          table.on('toolbar(data-sysAchievement)', function(obj){
            var checkStatus = table.checkStatus(obj.config.id);
            switch(obj.event){
              case 'add':
                $.ajax({
                      url:"/sysAchievement/add",
                      success:function (html) {
                          openIndex= layer.open({
                              title:"添加",
                              type:1,
                              area: ['420px', '240px'],
                              content:html
                          });
                      }
                  });
              break;
              case 'getCheckLength':
                var data = checkStatus.data;
                layer.msg('选中了：'+ data.length + ' 个');
              break;
              case 'isAll':
                layer.msg(checkStatus.isAll ? '全选': '未全选');
              break;
            };
          });

        form.on('submit(btnSearch)', function(data){
         tableIns.reload({
           where: data.field
           ,page:{
            curr:1
           }
         });
          return false; //阻止表单跳转。如果需要表单跳转，去掉这段即可。
        });

        table.on('tool', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {

            } else if (obj.event === 'del') {
                layer.confirm('确定删除?', function (index) {
                    $.ajax({
                        url: "/sysAchievement/delSysAchievement",
                        data: {"id": data.id},
                        type: "post",
                        dataType: "json",
                        success: function (j) {
                            if (j.code == 0) {
                                layer.msg(j.msg);
                                obj.del();
                            }
                        }
                    });
                });
            } else if (obj.event === 'edit') {
                $.ajax({
                    url:"/sysAchievement/update",
                    success:function (html) {
                        openIndex= layer.open({
                            title:"修改",
                            type:1,
                            area: ['500px', '600px'],
                            content:html
                        });
                        form.val("sysAchievementForm",data);
                    }
                });
            }
        });
    });
</script>

<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">查看</a>
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>

<script type="text/html" id="toolbarDemo">
  <div class="layui-btn-container">
    <button class="layui-btn layui-btn-sm" lay-event="add">添加</button>
    <button class="layui-btn layui-btn-sm" lay-event="getCheckLength">获取选中数目</button>
    <button class="layui-btn layui-btn-sm" lay-event="isAll">验证是否全选</button>
  </div>
</script>